package com.xianggu.Collection.demo;

import com.xianggu.Collection.queue.BlockQueue;
import com.xianggu.Collection.queue.XiangGuQueue;
import com.xianggu.schedule.ScheduleService;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author chengjy
 * @date 2025/3/24
 */
public class QueueDemo {

    private static ScheduleService scheduleService = new ScheduleService();
    public static void main(String[] args) throws InterruptedException {
        BlockQueue<Integer> queue = new BlockQueue<>(2);

        scheduleService.schedule(new Runnable() {
            @Override
            public void run() {
                Integer dequeue = queue.dequeue();
                System.out.println(Thread.currentThread().getName() + " 消费者获取到元素：" + dequeue);
            }
        } , 1000);

        AtomicInteger dequeue = new AtomicInteger();
        scheduleService.schedule(new Runnable() {
            @Override
            public void run() {
                queue.enqueue(dequeue.incrementAndGet());
                System.out.println(Thread.currentThread().getName() + " 生产者生成元素：" + dequeue);
            }
        } , 500);

    }
}
